import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import {
    InputButton,
    DelDataButton,
    ExecuteButton,
    OpenExcelButton,
    SelectExcelButton,
    CommonButton,
} from '../Common/options'

const { hostname } = window.location

export const GetProjectScore = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    let data = {
        type: '项目评分',
        pageSize: 10,
        params: { pageIndex: 1, scoreType: 1 },
        get: API_LIST()[`getScoreManagementGetProjectScore`],
        added: `posScoreManagement`,
        modify: `putScoreManagement`,
        delete: `delScoreManagement`,
        initialValues: { scoreType: 1 },
        options: [
            <SelectExcelButton
                key="excel"
                title="下载Excel"
                OptionsEvent={OptionsEvent}
                api={API_LIST()['getProjectScoreListExcel']}
            />,
            hostname === 'jszx.ljkjkf.com' && (
                <CommonButton
                    key="submit"
                    OptionsEvent={OptionsEvent}
                    title="发布评分"
                    data={{
                        type: 'YearMonthSelectModal',
                        width: 800,
                        url: 'posScoreManagementPublishScore',
                        subText: '发布',
                        params: 'yearMonth',
                    }}
                />
            ),
            hostname === 'jszx.ljkjkf.com' && (
                <CommonButton
                    key="submit"
                    OptionsEvent={OptionsEvent}
                    title="删除评分"
                    danger={true}
                    data={{
                        type: 'YearMonthSelectModal',
                        width: 800,
                        url: 'posScoreManagementDeletePublishScore',
                        subText: '删除',
                        params: 'yearMonth',
                    }}
                />
            ),
        ],
        columns: [
            commonTableList.uuid,
            {
                dataIndex: 'projectUuid',
                title: '项目名称',
                valueType: 'select',
                valueEnum: ClientData.project,
                rules: true,
                width: 450,
            },
            {
                dataIndex: 'yearMonth',
                title: '年月',
                valueType: 'Date',
                picker: 'month',
                rules: true,
                width: 100,
            },
            {
                dataIndex: 'yProjectScore',
                title: '原分数',
                valueType: 'input',
                rules: true,
                width: 100,
                hideInSearch: true,
            },
            {
                dataIndex: 'problemScore',
                title: '问题分',
                valueType: 'input',
                rules: true,
                width: 100,
                hideInSearch: true,
            },
            {
                dataIndex: 'addScore',
                title: '加分',
                valueType: 'input',
                rules: true,
                width: 100,
                hideInSearch: true,
            },
            {
                dataIndex: 'projectScore',
                title: '最终得分',
                valueType: 'input',
                rules: true,
                width: 100,
                hideInSearch: true,
            },
            {
                dataIndex: 'isEnabled',
                title: '审核',
                valueType: 'select',
                valueEnum: { 0: '未通过', 1: '已通过' },
                rules: true,
                width: 100,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 500,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { projectUuid, yearMonth, isEnabled } = record
                    return [
                        Permission.findIndex(v => v.uuid === 'a620a83d-8bf8-4c3f-9cc4-8499dd36e873') !== -1 && (
                            <ExecuteButton
                                actionRef={actionRef}
                                key="generate"
                                title="生成评分"
                                url="getScoreManagementProduceProjectScore"
                                data={{ projectUuid, yearMonth }}
                                tips="评分生成成功!"
                            />
                        ),
                        Permission.findIndex(v => v.uuid === 'b3007b6b-5374-4146-b593-768b13abc83b') !== -1 && (
                            <OpenExcelButton
                                key="open"
                                title="评分详情"
                                OptionsEvent={OptionsEvent}
                                data={{
                                    save: true,
                                    url: 'getScoreManagementGetProjectScoreExcel',
                                    projectUuid,
                                    yearMonth,
                                }}
                            />
                        ),
                        <OpenExcelButton
                            key="thr"
                            title="标段排名"
                            OptionsEvent={OptionsEvent}
                            data={{
                                save: true,
                                url: 'getWinningBidderScoreListExcelByProjectUuid',
                                projectUuid,
                                yearMonth,
                            }}
                        />,

                        Permission.findIndex(v => v.uuid === '812ad980-381a-4e83-b88f-d358ebb70189') !== -1 &&
                            isEnabled === 0 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="通过"
                                    url="posScoreManagementUpdateProjectScoreIsEnabled"
                                    path={[projectUuid, yearMonth, 1]}
                                    tips="数据通过成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === '812ad980-381a-4e83-b88f-d358ebb70189') !== -1 &&
                            isEnabled === 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="two"
                                    title="不通过"
                                    danger={true}
                                    url="posScoreManagementUpdateProjectScoreIsEnabled"
                                    path={[projectUuid, yearMonth, 0]}
                                    tips="数据不通过成功!"
                                />
                            ),
                        <InputButton
                            key="put"
                            OptionsEvent={OptionsEvent}
                            title="加分"
                            data={{
                                record,
                                actionRef,
                                label: '分数',
                                smallTitle: '增加分数',
                                url: 'posScoreManagementAddProjectScore',
                                field: 'addScore',
                            }}
                        />,
                        <DelDataButton
                            OptionsEvent={OptionsEvent}
                            key="del"
                            title="删除"
                            way="post"
                            url="posScoreManagementRemoveProjectScoreManagement"
                            uuid={[projectUuid, yearMonth]}
                        />,
                    ]
                },
            },
        ],
    }
    return data
}
